package demo;

import com.luoye.lson.Lson;
import java.util.*;

public class Main {

    public static void main(String[] args)  {
        String json = toJson();
        System.out.println("toJson = " + json);
        GameMap gameMap = toObject(json);
        System.out.println("toObject = " + gameMap);
    }

    private static String toJson(){
        Npc boss = new Npc("绿皮怪",135,758,20,20,new Skill("火球",12));
        List<MapObject> list = new ArrayList<>();
        list.add(boss);
        for (int i = 0; i < 5; i++) {
            Npc npc = new Npc("蓝蛇", i * 10 + 2,233,40,20,new Skill("毒液",4));
            list.add(npc);
        }
        GameMap gameMap = new GameMap("新罗大陆",1024,512,list,new int[]{1,0,2,1,1,1,1,2});
        String json = Lson.toJson(gameMap);
        return json;
    }

    private static GameMap toObject(String json) {
        return Lson.toObject(json, GameMap.class);
    }

}
